﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Prajob : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count == 0)
        {
            ImageButton1.Visible = false;
            ImageButton2.Visible = false;
        }
        else
        {
            ImageButton1.Visible = true;
            ImageButton2.Visible = true;
        }
        Label1.Text = "";
        if (Request.QueryString["qy"] != null)
        {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + "and tb_comwant.cpid=" + Request.QueryString["qy"].ToString();
        }
        if (Request.QueryString["hy"] != null)
        {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + "and tb_comwant.trid=" + Request.QueryString["hy"].ToString();
            return;
        }
        if (Request.QueryString["time"] != null)
        {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + "and tb_comwant.cwtime='" + Request.QueryString["time"].ToString() + "'";
            return;
        } if (Request.QueryString["add"] != null)
        {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + "and cwjobadd='" + Request.QueryString["add"].ToString() + "'";
            return;
        } if (Request.QueryString["xl"] != null)
        {
            SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + "and tb_comwant.cwknowledge='" + Request.QueryString["xl"].ToString() + "'";
            
        }
    }
    private TBjobapply jba;
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        //申请职位
        if (Session["person"] != null)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox txt = (CheckBox)GridView1.Rows[i].Cells[5].FindControl("CheckBox1");
                if (txt.Checked == true)
                {
                    JobApply job = new JobApply();
                    string val = GridView1.DataKeys[i].Value.ToString();
                    jba = new TBjobapply();
                    jba.Pid = Session["person"].ToString();
                    jba.Cwid = Convert.ToInt32(val);
                    if (job.isapply(jba).Equals("0"))
                    {
                        job.jobapply(jba);
                    }
                    else
                    {
                        Label1.Text = "<script>alert('" + i + "行工作申请重复！');</script>";
                        return;
                    }
                }
                Label1.Text = "<script>alert('申请成功！');window.opener.location.reload();</script>";
            }
           
        }
        else
        {
            Label1.Text = "<script>alert('请登录！');window.location.href='Default.aspx';</script>";
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox txt = (CheckBox)GridView1.Rows[i].Cells[5].FindControl("CheckBox1");
            txt.Checked = false;
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        SqlDataSource2.SelectCommand = "SELECT tb_comwant.cwid, tb_comwant.cpid, tb_comwant.trid, tb_comwant.cwname, tb_comwant.cwask, tb_comwant.cwdeal, tb_comwant.cwjobadd, tb_comwant.cwpersonnum, tb_comwant.cwtime, tb_comwant.jcid, tb_company.cpname, tb_trade.trname, tb_jobclass.jcname, tb_company.cphref, tb_comwant.cwknowledge FROM tb_comwant INNER JOIN tb_trade ON tb_comwant.trid = tb_trade.trid INNER JOIN tb_company ON tb_comwant.cpid = tb_company.cpid INNER JOIN tb_jobclass ON tb_comwant.jcid = tb_jobclass.jcid WHERE (tb_jobclass.jcname = '实习招聘' and chandle='允许')";
    }
}
